import { Component } from '@angular/core';
import { Storage } from '@ionic/storage';
import { NavController, LoadingController, ToastController } from 'ionic-angular';

import { EditProfilePage } from './edit/edit';
import { FanService } from '../../providers/fan';

@Component({
	selector: 'page-profile',
	templateUrl: 'profile.html',
	providers: [FanService]
})
export class ProfilePage {

	oId: string;
	editProfilePage: any;
	profile: any = {
		name: '',
		birthday: '',
		telphone: '',
		nick_name: ''
	};

	constructor(
		private navCtrl: NavController,
		private fanService: FanService,
		private loadingCtrl: LoadingController,
		private toastCtrl: ToastController,
		private storage: Storage
	) {
		this.editProfilePage = EditProfilePage;
	};

	ionViewWillEnter() {
		let loading = this.loadingCtrl.create({
			spinner: 'circles'
		});
		// loading.present();
		this.storage.get('openid').then(v => {
			this.oId = v;
			this.fanService.getProfile(this.oId).then(result => {
				this.profile = result;
				loading.dismiss();
			})
		})
	};

	goToEdit() {
		this.navCtrl.push(this.editProfilePage, {
			'profile': this.profile
		})
	};
}
